<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head th:replace="fragments/header :: common-header">
    <title>景点管理 - 景点投票系统</title>
</head>
<body>
<div th:replace="fragments/navbar :: navbar"></div>

<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>景点管理</h2>
        <a th:href="@{/spot/add}" class="btn btn-primary">
            <i class="fas fa-plus"></i> 添加景点
        </a>
    </div>

    <div th:if="${#lists.isEmpty(spots)}" class="alert alert-info">
        暂无景点数据，请先添加景点。
    </div>

    <div th:unless="${#lists.isEmpty(spots)}" class="card shadow-sm">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>景点名称</th>
                        <th>描述</th>
                        <th>位置</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="spot : ${spots}">
                        <td th:text="${spot.id}"></td>
                        <td th:text="${spot.name}"></td>
                        <td>
                                    <span th:if="${#strings.length(spot.description) > 20}"
                                          th:attr="title=${spot.description}"
                                          th:text="${#strings.substring(spot.description, 0, 20)} + '...'"></span>
                            <span th:unless="${#strings.length(spot.description) > 20}"
                                  th:text="${spot.description} ?: '-'"></span>
                        </td>
                        <td th:text="${spot.location} ?: '-'"></td>
                        <td th:text="${#temporals.format(spot.createTime, 'yyyy-MM-dd HH:mm')}"></td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a th:href="@{'/spot/edit/' + ${spot.id}}" class="btn btn-outline-primary">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                <a th:href="@{'/spot/delete/' + ${spot.id}}" class="btn btn-outline-danger"
                                   onclick="return confirm('确定要删除这个景点吗？')">
                                    <i class="fas fa-trash"></i> 删除
                                </a>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>